import { defineStore } from "pinia";

export const useTodoStore = defineStore('todo', {
  state: () => ({
    list: [
      { id: 1, text: '事项1', status: 'active'},
      { id: 2, text: '事项2', status: 'active'},
      { id: 3, text: '事项3', status: 'active'},
      { id: 4, text: '事项4', status: 'active'},
      { id: 5, text: '', status: 'empty'}            
    ]
  }),
  actions: {
    create() {
      const emptySlot = this.list.find(item => item.status === 'empty')
      if (emptySlot) {
        emptySlot.text = `新待办 ${new Date().toLocaleTimeString()}`
        emptySlot.status = 'active'
      }
    },
    remove(id) {
      const item = this.list.find(item => item.id === id)
      if (item) {
        item.text = ''
        item.status = 'empty'
      }
    },
    editText(id, newText) {
      const item = this.list.find(item => item.id === id)
      if (item) {
        item.text = newText
      }
    }
  }
})